JavaScript Mapper Prerender Policy Function
Once Policy Manager determines which policies should be exported to a device, it uses your mapper's preRenderPolicy method to individually transform each policy entity and send it to your export template. At first, this method may seem to be redundant with the Jinja2 export template. However, some transformations are more succinct, understandable, and performant to implement in a JavaScript function than they are directly in a Jinja2 template. The preRenderPolicy takes a single argument, which is a policy entity. It may return an arbitrary piece of data. That data will be passed into your export template.
Examples
Example of a Policy Manager policy entity:
{
"name": "pm-test-ext-1",
"policyType": "acl",
"addressType": "IPv4",
"rules": [
{
"name": "pm-test-ext-1_rule0",
"enabled": true,
"policyType": "acl",
"action": "permit",
"sourceNetworks": [
{
"addressType": "IPv4",
"canonical": "0.0.0.0/0",
"address": "0.0.0.0",
"prefixLength": 0,
"netmask": "0.0.0.0",
"hostmask": "255.255.255.255"
}
],
"destinationNetworks": [
{
"addressType": "IPv4",
"canonical": "0.0.0.0/0",
"address": "0.0.0.0",
"prefixLength": 0,
"netmask": "0.0.0.0",
"hostmask": "255.255.255.255"
}
],
"services": [
{
"traffic": {
"protocol": 6
}
}
]
},
{
"name": "pm-test-ext-1_rule1",
"enabled": true,
"policyType": "acl",
"action": "permit",
"sourceNetworks": [
{
"addressType": "IPv4",
"canonical": "0.0.0.0/0",
"address": "0.0.0.0",
"prefixLength": 0,
"netmask": "0.0.0.0",
"hostmask": "255.255.255.255"
}
],
"destinationNetworks": [
{
"addressType": "IPv4",
"canonical": "0.0.0.0/0",
"address": "0.0.0.0",
"prefixLength": 0,
"netmask": "0.0.0.0",
"hostmask": "255.255.255.255"
}
],
"services": [
{
"traffic": {
"protocol": 1
}
}
]
}
]
}
Example of a transformed object from Policy Manager's Cisco IOS integration:
{
"name": "pm-test-ext-1",
"policyType": "acl",
"addressType": "IPv4",
"rules": [
{
"name": "pm-test-ext-1_rule0",
"enabled": true,
"policyType": "acl",
"action": "permit",
"sourceNetworks": [
"any"
],
"destinationNetworks": [
"any"
],
"services": [
{
"traffic": {
"protocol": 6
},
"protocol": "tcp"
}
]
},
{
"name": "pm-test-ext-1_rule1",
"enabled": true,
"policyType": "acl",
"action": "permit",
"sourceNetworks": [
"any"
],
"destinationNetworks": [
"any"
],
"services": [
{
"traffic": {
"protocol": 1
},
"protocol": "icmp"
}
]
}
]
}